#*************************************************************************
#*
#*  $RCSfile$
#*
#*  $Revision$
#*
#*  last change: $Author: wiede $ $Date: 2005-10-19 17:46:51 +0200 (Wed, 19 Oct 2005) $
#*
#*  The Contents of this file are made available subject to the terms of
#*  the following license
#*
#* 	- BSD License
#*
#*	see file license/license.terms in this directory
#*
#*  Copyright 2005 Wolfgang Grosser
#*
#*  Author: Wolfgang Grosser
#*
#*  Contributor(s): 
#*
#************************************************************************/

package require tcluno_soffice
namespace eval ::tcluno::swriter {
	variable _allowedNumberingStyles
	set _allowedNumberingStyles [list \
			ParagraphStyles \
			CharacterStyles \
		]
}
proc ::tcluno::swriter::appendText {text textString style {newParagraph 1}} {
	set end [$text getEnd]
	if {$newParagraph} {
		$text insertControlCharacter $end 0 0
	}
	$end setString $textString
#	puts stderr "$end setPropertyValue ParaStyleName [lindex $style 0]"
	$end setPropertyValue ParaStyleName [lindex $style 0]
#	ToDo: a lot of more options, need another interface for this
#	as this is really hardcoded
	foreach {property value} [lindex $style 1] {
		$end setPropertyValue $property $value
	}
}
proc ::tcluno::swriter::getStyleFamilies {doc} {
	set styleFamilies [$doc getStyleFamilies]
	set counter [$styleFamilies getCount]
	return [$styleFamilies getElementNames]
}
proc ::tcluno::swriter::getStyles {doc styleType {active 1}} {
	set styleFamily [$doc getStyleFamilies]
	set family [$styleFamily getByName $styleType]
	set counter [$family getCount]
	set styles [list]
	for {set i 0} {$i < $counter} {incr i} {
		set style [$family getByIndex $i]
		if {$active} {
			if {[string length [$style isInUse]] > 0} {
				lappend styles [$style DisplayName]
			}
		} else {
			lappend styles [$style DisplayName]
		}
	}
	return $styles
}
proc ::tcluno::swriter::pdfExport {doc filename} {
	set sequence [$::tcluno_soffice::desktop tcluno::createUnoSequence Any]
	set filter [$::tcluno_soffice::desktop tcluno::createUnoStructHelper com.sun.star.beans.PropertyValue {FilterName -1 writer_pdf_Export 0}]
	$::tcluno_soffice::desktop tcluno::appendUnoSequence $sequence $filter
	$doc storeToURL $filename $sequence
}

package provide tcluno_swriter 0.0
